home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / FACTORY.PY < prev    next >
Encoding:
Text File  |  2000-08-14  |  7.0 KB  |  188 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. __doc__='''Factory objects
  65.  
  66. $Id: Factory.py,v 1.17.18.3 2000/08/14 14:47:51 shane Exp $'''
  67. __version__='$Revision: 1.17.18.3 $'[11:-2]
  68.  
  69. import OFS.SimpleItem, Acquisition, Globals, AccessControl.Role
  70. import Products, Product
  71.  
  72. class Factory(
  73.     AccessControl.Role.RoleManager,
  74.     Globals.Persistent, Acquisition.Implicit, OFS.SimpleItem.Item
  75.     ):
  76.     "Model factory meta-data"
  77.     meta_type='Zope Factory'
  78.     icon='p_/Factory_icon'
  79.  
  80.     permission='' # Waaaa
  81.  
  82.     _setObject=_getOb=Acquisition.Acquired
  83.  
  84.     __ac_permissions__=(
  85.         ('Edit Factories', ('manage_edit','manage_main')),
  86.         ('Use Factories', ('index_html','')),
  87.         )
  88.  
  89.     manage_options=(
  90.         (
  91.         {'label':'Edit', 'action':'manage_main',
  92.          'help':('OFSP','Zope-Factory_Edit.stx')},
  93.         )
  94.         +AccessControl.Role.RoleManager.manage_options
  95.         +OFS.SimpleItem.Item.manage_options
  96.         )
  97.     
  98.     def __init__(self, id, title, object_type, initial, permission=''):
  99.         self.id=id
  100.         self.title=title
  101.         self.object_type=object_type
  102.         self.initial=initial
  103.         self.permission=permission
  104.  
  105.     initializePermission__roles__ = ()
  106.     def initializePermission(self):
  107.         self.manage_setPermissionMapping(('Use Factories',),
  108.                                          (self.permission,))
  109.  
  110.     def manage_edit(self, title, object_type, initial, permission='',
  111.                     REQUEST=None):
  112.         "Modify factory properties."
  113.         self._unregister()
  114.         self.title=title
  115.         self.object_type=object_type
  116.         self.initial=initial
  117.         self.permission=permission
  118.         self.manage_setPermissionMapping(('Use Factories',), (permission,))
  119.         self._register()
  120.         if REQUEST is not None: return self.manage_main(self, REQUEST)
  121.  
  122.     def manage_afterAdd(self, item, container):
  123.         if hasattr(self, 'aq_parent'):
  124.             container=self.aq_parent
  125.         elif item is not self:
  126.             container=None
  127.         if (item is self or
  128.             getattr(container, '__class__', None) is Product.Product):
  129.             self._register()
  130.  
  131.     def manage_beforeDelete(self, item, container):
  132.         if hasattr(self, 'aq_parent'):
  133.             container=self.aq_parent
  134.         elif item is not self:
  135.             container=None
  136.  
  137.         if (item is self or
  138.             getattr(container, '__class__', None) is Product.Product):
  139.             self._unregister()
  140.  
  141.     def _register(self):
  142.         # Register with the product folder
  143.         product=self.aq_parent
  144.         product.aq_acquire('_manage_add_product_meta_type')(
  145.             product, self.id, self.object_type, self.permission)
  146.  
  147.     def _unregister(self):
  148.         # Unregister with the product folder
  149.         product=self.aq_parent
  150.         product.aq_acquire('_manage_remove_product_meta_type')(
  151.             product, self.id, self.object_type)
  152.  
  153.     manage_main=Globals.HTMLFile('editFactory',globals())
  154.  
  155.     def index_html(self, REQUEST):
  156.         " "
  157.         return getattr(self, self.initial)(self.aq_parent, REQUEST)
  158.  
  159.     def objectIds(self):
  160.         return filter(
  161.             lambda id, myid=self.id: id != myid,
  162.             self.aq_parent.objectIds()
  163.             )
  164.  
  165. class ProductFactory(Factory): pass
  166.     
  167.